fix(hooks): prevent stdin drain from skipping subsequent hooks#165
fix(hooks): prevent stdin drain from skipping subsequent hooks#165helizaga merged 7 commits intocoderabbitai:mainfrom
Conversation
Add </dev/null to hook subshell to prevent commands that read stdin (e.g. cat, read) from consuming the heredoc that feeds hook lines, which caused all subsequent hooks to be silently skipped. Fixes coderabbitai#164
Verify that a hook running `cat` (which reads stdin) does not prevent subsequent hooks from executing.
Add </dev/null to eval in run_hooks_export so hooks that read stdin (e.g. cat, read) do not consume the heredoc feeding hook lines, which caused subsequent postCd hooks to be silently skipped. Also adds a regression test for the postCd case.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughRedirected stdin for hook execution to Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes #164
All hook phases (
postCreate,preRemove,postRemove,postCd) suffered from the same bug: a hook that reads from stdin (e.g.cat,read) drains the hook list input, causing all subsequent hooks to be silently skipped.run_hooks: add</dev/nullto the hook subshell(...) </dev/nullrun_hooks_export: add</dev/nullto theevalcall (eval "$hook" </dev/null)initshell integration (bash/zsh): add</dev/nullto generatedpostCdhook execution sogit gtr cdandgit gtr new --cdare covered tooThese changes prevent hook commands from inheriting the hook list as stdin while preserving existing behavior such as env var exports, exit code handling, and shell integration semantics.
Test plan
postCreate,preRemove, andpostRemoveverifycatbetween two hooks does not skip the thirdpostCdviarun_hooks_exportinitbash/zshwrappers verifygtr_run_post_cd_hookscontinues after a stdin-reading hookbats tests/hooks.batsbats tests/init.batsSummary by CodeRabbit
Bug Fixes
Tests